package com.hogocloud.myframe.ui;

import android.os.Bundle;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.hogocloud.corelibrary.base.BaseActivity;
import com.hogocloud.corelibrary.utils.StatusBarUtils;
import com.hogocloud.myframe.R;
import com.hogocloud.myframe.adapter.PhotoDragCallBack;
import com.hogocloud.myframe.adapter.ReadDragAdapter;
import com.hogocloud.myframe.data.bean.SelectItemBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author GaoJunchao
 * @date 2020-04-14
 */
public class SelectItemActivity extends BaseActivity {

    private RecyclerView rvDrag;
    private ItemTouchHelper itemTouchHelper;

    @Override
    public int initLayout() {
        return R.layout.activity_select_item;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        rvDrag = findViewById(R.id.rv_drag);

        ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) rvDrag.getLayoutParams();
        params.topMargin = StatusBarUtils.INSTANCE.getStatusBarHeight(this);
        rvDrag.requestLayout();

        initData();
    }

    private void initData() {
        List<SelectItemBean> top = new ArrayList();
        top.add(new SelectItemBean(0, R.drawable.ic_tomato, 0, true, false));
        top.add(new SelectItemBean(1, R.drawable.ic_tomato, 0, true, false));
        top.add(new SelectItemBean(2, R.drawable.ic_tomato, 0, true, false));
        top.add(new SelectItemBean(3, R.drawable.ic_tomato, 0, true, false));
        top.add(new SelectItemBean(4, R.drawable.ic_tomato, 0, true, false));

        top.add(new SelectItemBean(0, R.drawable.ic_baskit, 0, true, false));
        top.add(new SelectItemBean(1, R.drawable.ic_baskit, 0, true, false));
        top.add(new SelectItemBean(2, R.drawable.ic_baskit, 0, true, false));
        top.add(new SelectItemBean(3, R.drawable.ic_baskit, 0, true, false));
        top.add(new SelectItemBean(4, R.drawable.ic_baskit, 0, true, false));

        ReadDragAdapter topAdapter = new ReadDragAdapter();
        rvDrag.setLayoutManager(new GridLayoutManager(this, top.size() / 2));
        PhotoDragCallBack callBack = new PhotoDragCallBack(topAdapter, top);
        itemTouchHelper = new ItemTouchHelper(callBack);
        itemTouchHelper.attachToRecyclerView(rvDrag);
        rvDrag.setAdapter(topAdapter);
        topAdapter.setData(top, top.size() / 2);

        topAdapter.addOnItemTouchListener(holder -> {
            itemTouchHelper.startDrag(holder);
        });
        callBack.setDragListener(new PhotoDragCallBack.DragListener() {
            @Override
            public void deleteState(boolean delete) {

            }

            @Override
            public void dragState(boolean start) {

            }

            @Override
            public void clearView() {

            }
        });
    }

}
